/*
Arm Tracker and Glove Demo by Noah Zerkin (noazark AT gmail.com) 2009
Released under GNU GPLv3.0 http://www.opensource.org/licenses/gpl-3.0.html
*/

class MenuObj extends VRObj{
  
  String[] menuItem = new String[4];
  int[][] menuItemCoords = new int[4][3];
  int menuItemSelected = 4;
  
  MenuObj(String menuItem1, String menuItem2, String menuItem3, String menuItem4){
    menuItem[0] = menuItem1;
    menuItem[1] = menuItem2;
    menuItem[2] = menuItem3;
    menuItem[3] = menuItem4;
    menuItemCoords[0][0] = 0; menuItemCoords[0][1] = 40; menuItemCoords[0][2] = 0;
    menuItemCoords[1][0] = 0; menuItemCoords[1][1] = -40; menuItemCoords[1][2] = 0;
    menuItemCoords[2][0] = 70; menuItemCoords[2][1] = 0; menuItemCoords[2][2] = 0;
    menuItemCoords[3][0] = -70; menuItemCoords[3][1] = 0; menuItemCoords[3][2] = 0;
  }
  
  void update(){
      mObj[0] = hudX; mObj[1] = hudY; mObj[2] = hudZ;
      pushMatrix();
      translate(hudX,hudY,hudZ);
      rotateY(HALF_PI+radians(vr920yaw));
      rotateX(-radians(vr920pitch));
      stroke(#FF0000);
      fill(#ADFF2F, 60);
      ellipseMode(CENTER);
      rectMode(CENTER);
      textAlign(CENTER);
      menuItemSelection();
      if(menuItemSelected != 4){
        fill(#ADFF2F);
      }
      ellipse(0,0,15,15);
      for(int i=0;i<4;i+=1){
        menuItemBox(i);
      }
      popMatrix();
  }
  void menuItemSelection(){
    if(joyX > 30 && abs(joyY) < 20){
      menuItemSelected = 3;
    }
    else{if(joyX < -30 && abs(joyY) < 20){
      menuItemSelected = 2;}
    else{if(abs(joyX) < 20 && joyY < -30){
      menuItemSelected = 0;}
    else{if(abs(joyX) < 20 && joyY > 30){
      menuItemSelected = 1;
    }
    else{menuItemSelected = 4;}
  }}}}
  
  void menuItemBox(int menuItemNumber){
        fill(#ADFF2F, 120);
        if(menuItemSelected == menuItemNumber){
          fill(#ADFF2F);
        }
        pushMatrix();
        translate(menuItemCoords[menuItemNumber][0],menuItemCoords[menuItemNumber][1],menuItemCoords[menuItemNumber][2]);
        rect(0,0,90,35);
        pushMatrix();
        rotateY(PI);
        fill(#FF0000);
        translate(0,0,1);
        text(menuItem[menuItemNumber],0,0);
        popMatrix();
      popMatrix();
  }
}
